<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class upVideo_manag extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('file');
        $this->load->helper('form');
        $this->load->database();
        $this->load->helper('func');
        $this->load->model('alblum_process');
        $this->load->model('video_process');
        $this->load->library('file_upload'); //引入类库
    }

    public function index() {
        $this->load->library('oss/ALIOSS');
        $bucket = 'favorite_app';
        $options = array(
            'delimiter' => '/',
            'prefix' => '',
            'max-keys' => 10,
                //'marker' => 'myobject-1330850469.pdf',
        );
        $response = $this->alioss->list_object($bucket, $options);
        $data['bucket_url'] = $response->header['x-oss-request-url'];
        $response = json_decode(json_encode(simplexml_load_string($response->body)), TRUE); //xml转成数组
        $data['flv'] = $response['Contents'];

        //获取album分类
        $data["album_cats"] = $this->alblum_process->album_type_array(1);
        $data["video_list"] = $this->video_process->video_list(); //获取已经插入数据库的数据
        //print_r($data['flv']);

        foreach ($data['flv'] as $key => $val) {
            foreach ($data["video_list"] as $k => $v) {
              if(strstr($v["path"],$val["Key"])){
                  unset($data['flv'][$key]);
              }
            }
        }
       // print_r($data['flv']);
        //exit;
        $this->load->view('admin/header_view', $data);
        $this->load->view('admin/upVideo_view');
        $this->load->view('admin/footer_view');
    }

    public function add_album() {
        $post_array = $_POST;
        $config['upload_path'] = './uploads/album'; //设定上传存储路径
        $data = $this->file_upload->upLoadfile($config, "cover");
        if (isset($data)) {
            $siteurl = site_url(); //$siteurl .
            $config["source_image"] = $data["full_path"];
            $config["new_image"] = './uploads/album/thum';
            $this->file_upload->process_img($config);
            $_POST["cover"] = "{$data["file_name"]}";
        } else {
            $_POST["cover"] = "";
        }
        $this->alblum_process->add_album($_POST);
        redirect('admin/upVideo_manag/');
        exit;
    }

    public function add_video() {
        $post_array = $_POST;
        $config['upload_path'] = './uploads/photos'; //设定上传存储路径
        $data = $this->file_upload->upLoadfile($config, "cover");
        if (isset($data)) {
            $siteurl = site_url(); //$siteurl .
            $config["source_image"] = $data["full_path"];
            $config["new_image"] = './uploads/photos/thum';
            $this->file_upload->process_img($config);
            $post_array["full_path"] = "{$data["file_name"]}";
        } else {
            $post_array["full_path"] = "";
        }

        $this->video_process->add_vedio($post_array);
        //  redirect("admin/menu_manag");
        // print_r($_POST);
      redirect('admin/upVideo_manag/');
    }

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */